package ExerciseTwo;



/*
 * 单例模式
 */
public class Test {
	public static void main(String[] args) {
		Today day1 = Today.getToday();
		Today day2 = Today.getToday();
		System.out.println(day1 == day2);
		A a1 = A.getA();
		A a2 = A.getA();
		System.out.println(a1 == a2);
		B b1 = B.getB();
		B b2 = B.getB();
		System.out.println(b1 == b2);
		
	}

}

class Today
{
	private static Today day= new Today();
	
	private Today()
	{
		
	}
	
	public static Today getToday()
	{
		return day;
	}
}

class A
{
	private static A a= new A();
	
	private A()
	{
		
	}
	
	public static A getA()
	{
		return a;
	}
}

class B 
{
	private static B b = null;
	
	private B()
	{
		
	}
	
	public static B getB()
	{
		if(b == null)
		{
			synchronized (B.class) {
				if(b == null)
				{
					b = new B();
				}
			}
		}
		return b;
	}
}